#!/usr/bin/perl
#
# (C) Copyright 2010- Hewlett-Packard Development Company, L.P.
#
#  $Id: MSA2000.pm 22886 2012-11-15 04:53:11Z yi.wang4@hp.com $
#


package Vdisk;

use strict;
use 5.008000;
use warnings;

sub new($)
{
    my $proto = shift;
    my $class = ref($proto) || $proto;
    my $self = {};

    $self->{NAME} = undef;
    $self->{RAID} = undef;
    $self->{DISKCOUNT} = undef;

    $self->{SLOTS} = [];
    $self->{VOLUMES}  = [];

    bless($self, $class);

    return ($self);
}

sub Name($;$)
{
    my $self = shift;
    my $name = shift;

    $self->{NAME} = $name if ($name);

    return ($self->{NAME});
}

sub DiskCount($;$)
{
    my $self = shift;
    my $diskcount = shift;

    $self->{DISKCOUNT} = $diskcount if ($diskcount);

    return ($self->{DISKCOUNT});
}

sub Raid($;$)
{
    my $self = shift;
    my $raid = shift;

    $self->{RAID} = $raid if ($raid);

    return ($self->{RAID});
}

sub Slots($)
{
    my $self = shift;

    return @{$self->{SLOTS}};
}

sub AddSlot($$)
{
    my $self = shift;
    my $slot = shift;

    push @{$self->{SLOTS}}, $slot;

    return ($self->{SLOTS});
}

sub Volumes($)
{
    my $self = shift;

    return @{$self->{VOLUMES}};
}

sub AddVolume($$)
{
    my $self = shift;
    my $volume = shift;

    push @{$self->{VOLUMES}}, $volume;

    return ($self->{VOLUMES});
}

sub RemoveVolumes($;@)
{
    my $self = shift;
    my @vols = @_;

    my @remain = @{$self->{VOLUMES}};

    for my $volname (@vols) {
        @remain = grep {$_->Name() ne $volname} @remain;
    }

    $self->{VOLUMES} = \@remain;
}

sub ToString($)
{
    my $self = shift;

    my $str = "$self->{NAME} => {Raid => $self->{RAID},"
            . " Diskcount => $self->{DISKCOUNT},"
            . " Slots => [" . join(",", $self->Slots()) . "],\n";

    for my $volume (sort $self->Volumes()) {
       $str .= '    ' . $volume->ToString() . "\n";
    }
    $str .= '}';

    return $str;
}

1;
